package com.sthz.facepay.service.impl;

import com.sthz.facepay.enums.ApiResultEnum;
import com.sthz.facepay.mapper.UserMapper;
import com.sthz.facepay.model.User;
import com.sthz.facepay.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * @author luli
 * @version jdk 1.8
 * @date 2019/7/12 16:14
 */
@Service
public class UserServiceImpl implements UserService {

    @Autowired
    UserMapper userMapper;

    @Override
    public boolean checkUser(String name, String password) {

        boolean flag = userMapper.checkUser(name,password);
        if(flag){
            return true;
        }
        return false;
    }

    @Override
    public User getUserByLoginName(String name) {
        return userMapper.getUserByLoginName(name);
    }

    @Override
    public User selectByPrimaryKey(Integer id) {
        return userMapper.selectByPrimaryKey(id);
    }

    /**
     *  修改用户信息
     * @param user
     * @return
     */
    @Override
    public int modifyUserInfo(User user) {
        boolean flag = userMapper.updateUserById(user);
        if (flag) {
            return ApiResultEnum.SUCCESS.getErrCode();
        }
        return ApiResultEnum.FAIL.getErrCode();
    }

    /**
     * 修改密码
     * @param password
     * @return
     */
    @Override
    public int modifyPassword(int id, String password) {
        boolean flag = userMapper.updateUserByPassword(id,password);
        if(flag){
            return ApiResultEnum.SUCCESS.getErrCode();
        }
        return ApiResultEnum.FAIL.getErrCode();
    }
}
